package com.trip.driver.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.trip.common.entity.Audit;
import com.trip.common.vo.DataDictionary;
import com.trip.common.vo.MyResultMap;
import com.trip.common.vo.Result;
import com.trip.driver.mapper.AuditMapper;
import com.trip.driver.service.AuditService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.HashMap;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author hr
 * @since 2024-09-05
 */
@Service
public class AuditServiceImpl extends ServiceImpl<AuditMapper, Audit> implements AuditService {

    @Autowired
    private AuditMapper auditMapper;

    @Override
    public Result applyBeDriver(Audit audit) {
        System.out.println(audit);
        int flag = auditMapper.applyBeDriver(audit);
        if (flag > 0){
            return Result.ok("申请成功");
        }else {
            return Result.error(DataDictionary.FAIL,"申请失败");
        }
    }

    @Override
    public Result getMyApply(Audit audit) {
        Audit myApply = auditMapper.getMyApply(audit);
        if (ObjectUtils.isEmpty(myApply)){
            return Result.error(DataDictionary.FAIL,"查询记录失败");
        }else {
            HashMap<String, Object> myResultMap = MyResultMap.getMyResultMap();
            myResultMap.put("data",myApply);
            return Result.ok("查询记录成功",myResultMap);
        }
    }
}
